function hideList() {
    parent.hideInquiryList();
}

layui.use(['form', 'layer', 'table'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table;

    //列表
    table.render({
        elem: '#list',
        url: $.cookie("tempUrl") + 'omsring/' + $.cookie("tempUrlTemp"),
        where: {
            // doctorId: $.cookie("doctorId"),
            // deptId: $.cookie("deptId")
        },
        method: "POST",
        response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            , statusCode: 200 //成功的状态码，默认：0
            , msgName: 'msg' //状态信息的字段名称，默认：msg
            , countName: 'totalElements' //数据总数的字段名称，默认：count
            , dataName: 'data' //数据列表的字段名称，默认：data
        },
        cellMinWidth: 95,
        height: "full-25",
        id: "dataTable",
        cols: [[
            {
                field: 'name', title: '姓名', minWidth: 100, align: 'center', templet: function (d) {
                    return d.name;
                }
            },
            {
                title: '性别', minWidth: 100, align: 'center', templet: function (d) {
                    switch (d.gender) {
                        case 1:
                            return "男";
                        case 2:
                            return "女";
                        default:
                            return "未设置";
                    }
                }
            },
            {
                title: '地域', minWidth: 100, align: 'center', templet: function (d) {
                    switch (d.ly) {
                        case 1:
                            return "本地";
                        case 2:
                            return "域外";
                    }
                }
            },
            {
                title: '发起时间', minWidth: 180, align: 'center', templet: function (d) {
                    return d.timeaa;
                }
            },
            {
                title: '类型', minWidth: 100, align: 'center', templet: function (d) {
                    switch ($.cookie("tempUrlTemp")) {
                        case 'findReceivingTreatmentRingPC?doctorId=' + $.cookie("doctorId"):
                            return '<a style="color: #FF5722" lay-event="zjSp" id=' + d.id + '>视频问诊<span class="layui-badge-dot"></span></a>';
                        case 'findGrabSheetList?deptId=' + $.cookie("deptId") + "&doctorId=" + $.cookie("doctorId"):
                            return '<a style="color: #FF5722" lay-event="look" id=' + d.id + '>视频问诊<span class="layui-badge-dot"></span></a>';
                        case 'finOmsImageTextAppVOList?doctorId=' + $.cookie("doctorId"):
                            if (d.yidu === 2) {
                                return '<a style="color: #FF5722" lay-event="lookTw" id=' + d.id + '>图文问诊<span class="layui-badge-dot"></span></a>';
                            }
                            return '<a style="color: #FFB800" lay-event="lookTw" id=' + d.id + '>图文问诊</a>';
                    }
                }
            },
        ]],
        done: function (res, curr, count) {
        }
    });

    //头部单选按钮事件
    //抢单列表
    form.on('radio(test0)', function (data) {
        table.reload("dataTable", {
            url: $.cookie("tempUrl") + 'omsring/' + $.cookie("tempUrlTemp"),
            where: {
                // doctorId: $.cookie("doctorId"),
                // deptId: $.cookie("deptId")
            },
            cols: [[
                {field: 'name', title: '姓名', minWidth: 100, align: 'center'},
                {
                    title: '性别', minWidth: 100, align: 'center', templet: function (d) {
                        switch (d.gender) {
                            case 1:
                                return "男";
                            case 2:
                                return "女";
                            default:
                                return "未设置";
                        }
                    }
                },
                {
                    title: '地域', minWidth: 100, align: 'center', templet: function (d) {
                        switch (d.ly) {
                            case 1:
                                return "本地";
                            case 2:
                                return "域外";
                        }
                    }
                },
                {
                    title: '发起时间', minWidth: 180, align: 'center', templet: function (d) {
                        return d.timeaa;
                    }
                },
                {
                    title: '类型', minWidth: 100, align: 'center', templet: function (d) {
                        switch ($.cookie("tempUrlTemp")) {
                            case 'findGrabSheetList?deptId=' + $.cookie("deptId"):
                                return '<a style="color: #FF5722" lay-event="look" id=' + d.id + '>视频问诊<span class="layui-badge-dot"></span></a>';
                            case 'finOmsImageTextAppVOList?doctorId=' + $.cookie("doctorId"):
                                if (d.yidu === 2) {
                                    return '<a style="color: #FF5722" lay-event="lookTw" id=' + d.id + '>图文问诊<span class="layui-badge-dot"></span></a>';
                                }
                                return '<a style="color: #FFB800" lay-event="lookTw" id=' + d.id + '>图文问诊</a>';
                        }
                    }
                },
            ]],
        });
    });
    //视频
    form.on('radio(test1)', function (data) {
        table.reload("dataTable", {
            url: $.cookie("tempUrl") + 'omsring/findGrabSheetList',
            where: {
                deptId: $.cookie("deptId")
            },
            cols: [[
                {field: 'name', title: '姓名', minWidth: 100, align: 'center'},
                {
                    title: '性别', minWidth: 100, align: 'center', templet: function (d) {
                        switch (d.gender) {
                            case 1:
                                return "男";
                            case 2:
                                return "女";
                            default:
                                return "未设置";
                        }
                    }
                },
                {
                    title: '地域', minWidth: 100, align: 'center', templet: function (d) {
                        switch (d.ly) {
                            case 1:
                                return "本地";
                            case 2:
                                return "域外";
                        }
                    }
                },
                {
                    title: '发起时间', minWidth: 180, align: 'center', templet: function (d) {
                        return d.timeaa;
                    }
                },
                {
                    title: '类型', minWidth: 100, align: 'center', templet: function (d) {
                        return '<a style="color: #FF5722" lay-event="look" id=' + d.id + '>视频问诊</a>';
                    }
                },
            ]],
        });
    });
    //图文
    form.on('radio(test2)', function (data) {
        table.reload("dataTable", {
            url: $.cookie("tempUrl") + 'omsring/finOmsImageTextAppVOList',
            where: {
                doctorId: $.cookie("doctorId")
            },
            cols: [[
                {field: 'name', title: '姓名', minWidth: 100, align: 'center'},
                {
                    title: '性别', minWidth: 100, align: 'center', templet: function (d) {
                        switch (d.gender) {
                            case 1:
                                return "男";
                            case 2:
                                return "女";
                            default:
                                return "未设置";
                        }
                    }
                },
                {
                    title: '地域', minWidth: 100, align: 'center', templet: function (d) {
                        switch (d.ly) {
                            case 1:
                                return "本地";
                            case 2:
                                return "域外";
                        }
                    }
                },
                {
                    title: '发起时间', minWidth: 180, align: 'center', templet: function (d) {
                        return d.timeaa;
                    }
                },
                {
                    title: '状态', minWidth: 100, align: 'center', templet: function (d) {
                        if (d.yidu === 2) {
                            return '<a style="color: #FF5722" lay-event="lookTw" id=' + d.id + '>立即处理</a>';
                        }
                        return '<a style="color: #FFB800" lay-event="lookTw" id=' + d.id + '>继续处理</a>';
                    }
                },
            ]],
        });
    });

    //头工具栏事件
    table.on('toolbar(test)', function (obj) {
        switch (obj.event) {
            case 'flash_btn':
                window.location.reload();
                break;
        }
    });

    //列表操作
    table.on('tool(test)', function (obj) {
        const layEvent = obj.event,//获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            data = obj.data;//获得当前行数据
        switch (layEvent) {
            //点击专家接单视频
            case 'zjSp':
                //隐藏侧边栏
                hideList();
                //调用抢单接口

                var rid = data.roomid;
                var ring2ly = data.ly;
                var ring2IP = data.ip;
                var ring2ym = data.yuming;
                var ring2rctid = data.rctid;
                var doctorId = $.cookie("doctorId");
                var userId = '';
                var tmpRoomId = data.roomid;
                var fwqbm = 'yjyl';
                if (ring2ly == "2") {
                    serverIP = ring2IP;
                    serverApi = "https://" + ring2ym + "/a02";
                    serverApi3 = "https://" + ring2ym + "/a03";
                    serverApi1 = "https://" + ring2ym + "/a01";
                    socketUrl6 = "wss://" + ring2ym + "/wss/websocket";
                    // dengMp3.pause();//暂停播放提示音
                    // layer.close(qangIndex);
                    // qangIndex = "";
                    //域外
                    //医生更换id
                    var reqData = {fwqbm: fwqbm, doctorId: doctorId};
                    $.ajax({
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                        url: serverApi + "/zy/findSysDoctorByFwqbmId" + "?" + formatParams(reqData),
                        success: function (result) {
                            console.log(JSON.stringify(result));
                            if (result.code === 200) {
                                doctorId = result.data;
                                userId = "doctor" + doctorId;

                                tmpRoomId = rid;
                                //普通接听
                                var reqData2 = {roomid: tmpRoomId, type: 1};
                                $.ajax({
                                    url: serverApi + "/omsring/updateOmsRing" + "?" + formatParams(reqData2),
                                    type: "POST",
                                    success: function (result) {
                                        console.log("抢单结果：" + JSON.stringify(result));
                                        if (result.code === 200) {
                                            //抢单成功操作
                                            let obj = {
                                                "roomId": data.id,
                                                "memberId": data.memberId,
                                                "sourceId": data.sourceId,
                                                "ly": data.ly,
                                                "ip": data.ip,
                                                "rctid": data.rctid,
                                                "yuming": data.yuming,
                                                "fwqmc": data.fwqmc,
                                                // "fwqbm": fwqbm,
                                                "ring2rctid": ring2rctid,
                                                "doctorId": doctorId,
                                                "userId": userId,
                                                "serverIP": serverIP,
                                                "serverApi": serverApi,
                                                "serverApi3": serverApi3,
                                                "serverApi1": serverApi1,
                                                "socketUrl6": socketUrl6,
                                            };
                                            sessionStorage.setItem('obj', JSON.stringify(obj));
                                            //设置为连接状态，连接结束前无法再抢单
                                            sessionStorage.setItem('tcpLink', "linking");
                                            // sessionStorage.setItem('grabSheetData', JSON.stringify(data));
                                            // console.log('grabSheetData:' + sessionStorage.getItem('grabSheetData'));
                                            var reqData = {roomid: data.id};
                                            $.ajax({
                                                type: "POST",
                                                contentType: "application/x-www-form-urlencoded",
                                                url: serverApi + "/omsring/findUmsMemberReceptionDeskVO" + "?" + formatParams(reqData),
                                                success: function (result) {
                                                    var ring = result.data;
                                                    if (ring != null && ring != "") {
                                                        $.cookie('memberId', ring.fmemberId, {path: '/'});
                                                        $.cookie('memberSid', ring.sid, {path: '/'});
                                                        let memberData = {
                                                            "age": ring.age,
                                                            "bloodPressure": ring.bloodPressure,
                                                            "bloodSugar": ring.bloodSugar,
                                                            "bodyFat": ring.bodyFat,
                                                            "chiefComplaint": ring.chiefComplaint,//主诉
                                                            "yaodianId": ring.cyydId,//常用药店id
                                                            "diagnosisId": ring.diagnosisId,//就诊记录id
                                                            "bqList": ring.bqList,//用户标签数组
                                                            "bsList": ring.bsList,//用户标签图片 字符串数组
                                                            "familyHistory": ring.familyHistory,//家族病史
                                                            "gender": ring.gender,//0未知,1男,2女
                                                            "heartRate": ring.heartRate,
                                                            "height": ring.height,//身高
                                                            "weight": ring.weight,//体重
                                                            "historyDrugAllergy": ring.historyDrugAllergy,//过敏史
                                                            "historySurgeryTrauma": ring.historySurgeryTrauma,//既往病史
                                                            "pastMedicalHistory": ring.pastMedicalHistory,//慢病
                                                            "icon": ring.icon,
                                                            "yaoList": ring.yaoList,//药品列表
                                                            "name": ring.name,//昵称
                                                            "yaodianName": ring.pharmacyName,//常用药店名称
                                                            "phone": ring.phone,//手机号
                                                            "sid": ring.sid,//身份证号
                                                            "sourceType": ring.sourceType,//权益来源 电信 移动 联通
                                                            "orderId": ring.orderId,//问诊订单id
                                                            "sfbd": ring.sfbd,//此患者是否当前医生的私有患者
                                                            "memberId": ring.fmemberId,//主患者id
                                                            "lsList": ring.lsList,
                                                            "fqPanelType": ring.panelType,//发起来源，1小程序，2app，3客户端
                                                            "fqType": ring.type,//当来源是客户端时，1药店，2机构
                                                            ///本次问诊信息
                                                            "symptomDuration": ring.symptomDuration,
                                                            "visitRecords": ring.visitRecords,
                                                            "diagnosisDisease": ring.diagnosisDisease,
                                                            "diagnosis": ring.diagnosis,
                                                            "conditionDescription": ring.conditionDescription,
                                                            "pictureIllness": ring.lsList,
                                                        };
                                                        sessionStorage.setItem('memberData', JSON.stringify(memberData));
                                                        // //若正在图文，立即中断，切换为视频
                                                        // sessionStorage.removeItem("changeLeft")
                                                        parent.window.location.reload();
                                                    }
                                                }, error: function () {
                                                    layer.msg("error")
                                                }
                                            });
                                            //jietingOne(roomId,"1");
                                        } else {
                                            //抢单失败操作
                                            layer.alert(result.msg, {icon: 7, anim: 6}, function (index) {
                                                //do something
                                                // parent.window.location.reload();
                                                layer.close(index);
                                            });
                                        }
                                    },
                                    error: function (result) {
                                        //未知异常操作
                                        layer.msg("未知异常")
                                    }
                                });

                            } else {
                                layer.msg("外部服务器调用失败：" + result.msg);
                            }
                        },
                        error: function (e) {
                            console.error("获得外部医生id失败！");
                        }
                    });
                    //域内
                } else {
                    userId = "doctor" + doctorId;
                    //普通接听
                    var reqData2 = {roomid: tmpRoomId, type: 1};
                    $.ajax({
                        url: $.cookie("tempUrl") + "omsring/updateOmsRing" + "?" + formatParams(reqData2),
                        type: "POST",
                        success: function (result) {
                            console.log("抢单结果：" + JSON.stringify(result));
                            if (result.code === 200) {
                                //抢单成功操作
                                let obj = {
                                    "roomId": data.id,
                                    "memberId": data.memberId,
                                    "sourceId": data.sourceId,
                                    "ly": data.ly,
                                    "ip": data.ip,
                                    "rctid": data.rctid,
                                    "yuming": data.yuming,
                                    "fwqmc": data.fwqmc,
                                    // "fwqbm": fwqbm,
                                    "ring2rctid": ring2rctid,
                                    "doctorId": $.cookie("doctorId"),
                                    "userId": userId,
                                    "serverIP": serverIP,
                                    "serverApi": serverApi,
                                    "serverApi3": serverApi3,
                                    "serverApi1": serverApi1,
                                    "socketUrl6": socketUrl6,
                                };
                                sessionStorage.setItem('obj', JSON.stringify(obj));
                                //设置为连接状态，连接结束前无法再抢单
                                sessionStorage.setItem('tcpLink', "linking");
                                // sessionStorage.setItem('grabSheetData', JSON.stringify(data));
                                // console.log('grabSheetData:' + sessionStorage.getItem('grabSheetData'));
                                var reqData = {roomid: data.id};
                                $.ajax({
                                    type: "POST",
                                    contentType: "application/x-www-form-urlencoded",
                                    url: serverApi + "/omsring/findUmsMemberReceptionDeskVO" + "?" + formatParams(reqData),
                                    success: function (result) {
                                        var ring = result.data;
                                        if (ring != null && ring != "") {
                                            $.cookie('memberId', ring.fmemberId, {path: '/'});
                                            $.cookie('memberSid', ring.sid, {path: '/'});
                                            let memberData = {
                                                "age": ring.age,
                                                "bloodPressure": ring.bloodPressure,
                                                "bloodSugar": ring.bloodSugar,
                                                "bodyFat": ring.bodyFat,
                                                "chiefComplaint": ring.chiefComplaint,//主诉
                                                "yaodianId": ring.cyydId,//常用药店id
                                                "diagnosisId": ring.diagnosisId,//就诊记录id
                                                "bqList": ring.bqList,//用户标签数组
                                                "bsList": ring.bsList,//用户标签图片 字符串数组
                                                "familyHistory": ring.familyHistory,//家族病史
                                                "gender": ring.gender,//0未知,1男,2女
                                                "heartRate": ring.heartRate,
                                                "height": ring.height,//身高
                                                "weight": ring.weight,//体重
                                                "historyDrugAllergy": ring.historyDrugAllergy,//过敏史
                                                "historySurgeryTrauma": ring.historySurgeryTrauma,//既往病史
                                                "pastMedicalHistory": ring.pastMedicalHistory,//慢病
                                                "icon": ring.icon,
                                                "yaoList": ring.yaoList,//药品列表
                                                "name": ring.name,//昵称
                                                "yaodianName": ring.pharmacyName,//常用药店名称
                                                "phone": ring.phone,//手机号
                                                "sid": ring.sid,//身份证号
                                                "sourceType": ring.sourceType,//权益来源 电信 移动 联通
                                                "orderId": ring.orderId,//问诊订单id
                                                "sfbd": ring.sfbd,//此患者是否当前医生的私有患者
                                                "memberId": ring.fmemberId,//主患者id
                                                "lsList": ring.lsList,
                                                "fqPanelType": ring.panelType,//发起来源，1小程序，2app，3客户端
                                                "fqType": ring.type,//当来源是客户端时，1药店，2机构
                                                ///本次问诊信息
                                                "symptomDuration": ring.symptomDuration,
                                                "visitRecords": ring.visitRecords,
                                                "diagnosisDisease": ring.diagnosisDisease,
                                                "diagnosis": ring.diagnosis,
                                                "conditionDescription": ring.conditionDescription,
                                                "pictureIllness": ring.lsList,
                                            };
                                            sessionStorage.setItem('memberData', JSON.stringify(memberData));
                                            // //若正在图文，立即中断，切换为视频
                                            // sessionStorage.removeItem("changeLeft")
                                            parent.window.location.reload();
                                        }
                                    }, error: function () {
                                        layer.msg("error")
                                    }
                                });
                                //jietingOne(roomId,"1");
                            } else {
                                //抢单失败操作
                                layer.alert(result.msg, {icon: 7, anim: 6}, function (index) {
                                    //do something
                                    // parent.window.location.reload();
                                    layer.close(index);
                                });
                            }
                        },
                        error: function (result) {
                            //未知异常操作
                            layer.msg("未知异常")
                        }
                    });
                }
                break;
            //点击接单视频
            case 'look':
                //隐藏侧边栏
                hideList();
                //调用抢单接口

                var rid = data.id;
                var ring2ly = data.ly;
                var ring2IP = data.ip;
                var ring2ym = data.yuming;
                var ring2rctid = data.rctid;
                var doctorId = $.cookie("doctorId");
                var userId = '';
                var tmpRoomId = data.id;
                var fwqbm = 'yjyl';
                if (ring2ly == "2") {
                    serverIP = ring2IP;
                    serverApi = "https://" + ring2ym + "/a02";
                    serverApi3 = "https://" + ring2ym + "/a03";
                    serverApi1 = "https://" + ring2ym + "/a01";
                    socketUrl6 = "wss://" + ring2ym + "/wss/websocket";
                    // dengMp3.pause();//暂停播放提示音
                    // layer.close(qangIndex);
                    // qangIndex = "";
                    //域外
                    //医生更换id
                    var reqData = {fwqbm: fwqbm, doctorId: doctorId};
                    $.ajax({
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                        url: serverApi + "/zy/findSysDoctorByFwqbmId" + "?" + formatParams(reqData),
                        success: function (result) {
                            console.log(JSON.stringify(result));
                            if (result.code === 200) {
                                doctorId = result.data;
                                userId = "doctor" + doctorId;

                                tmpRoomId = rid;
                                //普通接听
                                var reqData2 = {roomid: tmpRoomId, doctorid: doctorId};
                                $.ajax({
                                    url: serverApi + "/omsring/grabSheet" + "?" + formatParams(reqData2),
                                    type: "POST",
                                    success: function (result) {
                                        console.log("抢单结果：" + JSON.stringify(result));
                                        if (result.code === 200) {
                                            //抢单成功操作
                                            let obj = {
                                                "roomId": data.id,
                                                "memberId": data.memberId,
                                                "sourceId": data.sourceId,
                                                "ly": data.ly,
                                                "ip": data.ip,
                                                "rctid": data.rctid,
                                                "yuming": data.yuming,
                                                "fwqmc": data.fwqmc,
                                                // "fwqbm": fwqbm,
                                                "ring2rctid": ring2rctid,
                                                "doctorId": doctorId,
                                                "userId": userId,
                                                "serverIP": serverIP,
                                                "serverApi": serverApi,
                                                "serverApi3": serverApi3,
                                                "serverApi1": serverApi1,
                                                "socketUrl6": socketUrl6,
                                            };
                                            sessionStorage.setItem('obj', JSON.stringify(obj));
                                            //设置为连接状态，连接结束前无法再抢单
                                            sessionStorage.setItem('tcpLink', "linking");
                                            // sessionStorage.setItem('grabSheetData', JSON.stringify(data));
                                            // console.log('grabSheetData:' + sessionStorage.getItem('grabSheetData'));
                                            var reqData = {roomid: data.id};
                                            $.ajax({
                                                type: "POST",
                                                contentType: "application/x-www-form-urlencoded",
                                                url: serverApi + "/omsring/findUmsMemberReceptionDeskVO" + "?" + formatParams(reqData),
                                                success: function (result) {
                                                    var ring = result.data;
                                                    if (ring != null && ring != "") {
                                                        $.cookie('memberId', ring.fmemberId, {path: '/'});
                                                        $.cookie('memberSid', ring.sid, {path: '/'});
                                                        let memberData = {
                                                            "age": ring.age,
                                                            "bloodPressure": ring.bloodPressure,
                                                            "bloodSugar": ring.bloodSugar,
                                                            "bodyFat": ring.bodyFat,
                                                            "chiefComplaint": ring.chiefComplaint,//主诉
                                                            "yaodianId": ring.cyydId,//常用药店id
                                                            "diagnosisId": ring.diagnosisId,//就诊记录id
                                                            "bqList": ring.bqList,//用户标签数组
                                                            "bsList": ring.bsList,//用户标签图片 字符串数组
                                                            "familyHistory": ring.familyHistory,//家族病史
                                                            "gender": ring.gender,//0未知,1男,2女
                                                            "heartRate": ring.heartRate,
                                                            "height": ring.height,//身高
                                                            "weight": ring.weight,//体重
                                                            "historyDrugAllergy": ring.historyDrugAllergy,//过敏史
                                                            "historySurgeryTrauma": ring.historySurgeryTrauma,//既往病史
                                                            "pastMedicalHistory": ring.pastMedicalHistory,//慢病
                                                            "icon": ring.icon,
                                                            "yaoList": ring.yaoList,//药品列表
                                                            "name": ring.name,//昵称
                                                            "yaodianName": ring.pharmacyName,//常用药店名称
                                                            "phone": ring.phone,//手机号
                                                            "sid": ring.sid,//身份证号
                                                            "sourceType": ring.sourceType,//权益来源 电信 移动 联通
                                                            "orderId": ring.orderId,//问诊订单id
                                                            "sfbd": ring.sfbd,//此患者是否当前医生的私有患者
                                                            "memberId": ring.fmemberId,//主患者id
                                                            "lsList": ring.lsList,
                                                            "fqPanelType": ring.panelType,//发起来源，1小程序，2app，3客户端
                                                            "fqType": ring.type,//当来源是客户端时，1药店，2机构
                                                            ///本次问诊信息
                                                            "symptomDuration": ring.symptomDuration,
                                                            "visitRecords": ring.visitRecords,
                                                            "diagnosisDisease": ring.diagnosisDisease,
                                                            "diagnosis": ring.diagnosis,
                                                            "conditionDescription": ring.conditionDescription,
                                                            "pictureIllness": ring.lsList,
                                                        };
                                                        sessionStorage.setItem('memberData', JSON.stringify(memberData));
                                                        // //若正在图文，立即中断，切换为视频
                                                        // sessionStorage.removeItem("changeLeft")
                                                        parent.window.location.reload();
                                                    }
                                                }, error: function () {
                                                    layer.msg("error")
                                                }
                                            });
                                            //jietingOne(roomId,"1");
                                        } else {
                                            //抢单失败操作
                                            layer.alert(result.msg, {icon: 7, anim: 6}, function (index) {
                                                //do something
                                                // parent.window.location.reload();
                                                layer.close(index);
                                            });
                                        }
                                    },
                                    error: function (result) {
                                        //未知异常操作
                                        layer.msg("未知异常")
                                    }
                                });

                            } else {
                                layer.msg("外部服务器调用失败：" + result.msg);
                            }
                        },
                        error: function (e) {
                            console.error("获得外部医生id失败！");
                        }
                    });
                    //域内
                } else {
                    userId = "doctor" + doctorId;
                    //普通接听
                    var reqData2 = {roomid: tmpRoomId, doctorid: doctorId};
                    $.ajax({
                        url: $.cookie("tempUrl") + "omsring/grabSheet" + "?" + formatParams(reqData2),
                        type: "POST",
                        success: function (result) {
                            console.log("抢单结果：" + JSON.stringify(result));
                            if (result.code === 200) {
                                //抢单成功操作
                                let obj = {
                                    "roomId": data.id,
                                    "memberId": data.memberId,
                                    "sourceId": data.sourceId,
                                    "ly": data.ly,
                                    "ip": data.ip,
                                    "rctid": data.rctid,
                                    "yuming": data.yuming,
                                    "fwqmc": data.fwqmc,
                                    // "fwqbm": fwqbm,
                                    "ring2rctid": ring2rctid,
                                    "doctorId": $.cookie("doctorId"),
                                    "userId": userId,
                                    "serverIP": serverIP,
                                    "serverApi": serverApi,
                                    "serverApi3": serverApi3,
                                    "serverApi1": serverApi1,
                                    "socketUrl6": socketUrl6,
                                };
                                sessionStorage.setItem('obj', JSON.stringify(obj));
                                //设置为连接状态，连接结束前无法再抢单
                                sessionStorage.setItem('tcpLink', "linking");
                                // sessionStorage.setItem('grabSheetData', JSON.stringify(data));
                                // console.log('grabSheetData:' + sessionStorage.getItem('grabSheetData'));
                                var reqData = {roomid: data.id};
                                $.ajax({
                                    type: "POST",
                                    contentType: "application/x-www-form-urlencoded",
                                    url: serverApi + "/omsring/findUmsMemberReceptionDeskVO" + "?" + formatParams(reqData),
                                    success: function (result) {
                                        var ring = result.data;
                                        if (ring != null && ring != "") {
                                            $.cookie('memberId', ring.fmemberId, {path: '/'});
                                            $.cookie('memberSid', ring.sid, {path: '/'});
                                            let memberData = {
                                                "age": ring.age,
                                                "bloodPressure": ring.bloodPressure,
                                                "bloodSugar": ring.bloodSugar,
                                                "bodyFat": ring.bodyFat,
                                                "chiefComplaint": ring.chiefComplaint,//主诉
                                                "yaodianId": ring.cyydId,//常用药店id
                                                "diagnosisId": ring.diagnosisId,//就诊记录id
                                                "bqList": ring.bqList,//用户标签数组
                                                "bsList": ring.bsList,//用户标签图片 字符串数组
                                                "familyHistory": ring.familyHistory,//家族病史
                                                "gender": ring.gender,//0未知,1男,2女
                                                "heartRate": ring.heartRate,
                                                "height": ring.height,//身高
                                                "weight": ring.weight,//体重
                                                "historyDrugAllergy": ring.historyDrugAllergy,//过敏史
                                                "historySurgeryTrauma": ring.historySurgeryTrauma,//既往病史
                                                "pastMedicalHistory": ring.pastMedicalHistory,//慢病
                                                "icon": ring.icon,
                                                "yaoList": ring.yaoList,//药品列表
                                                "name": ring.name,//昵称
                                                "yaodianName": ring.pharmacyName,//常用药店名称
                                                "phone": ring.phone,//手机号
                                                "sid": ring.sid,//身份证号
                                                "sourceType": ring.sourceType,//权益来源 电信 移动 联通
                                                "orderId": ring.orderId,//问诊订单id
                                                "sfbd": ring.sfbd,//此患者是否当前医生的私有患者
                                                "memberId": ring.fmemberId,//主患者id
                                                "lsList": ring.lsList,
                                                "fqPanelType": ring.panelType,//发起来源，1小程序，2app，3客户端
                                                "fqType": ring.type,//当来源是客户端时，1药店，2机构
                                                ///本次问诊信息
                                                "symptomDuration": ring.symptomDuration,
                                                "visitRecords": ring.visitRecords,
                                                "diagnosisDisease": ring.diagnosisDisease,
                                                "diagnosis": ring.diagnosis,
                                                "conditionDescription": ring.conditionDescription,
                                                "pictureIllness": ring.lsList,
                                            };
                                            sessionStorage.setItem('memberData', JSON.stringify(memberData));
                                            // //若正在图文，立即中断，切换为视频
                                            // sessionStorage.removeItem("changeLeft")
                                            parent.window.location.reload();
                                        }
                                    }, error: function () {
                                        layer.msg("error")
                                    }
                                });
                                //jietingOne(roomId,"1");
                            } else {
                                //抢单失败操作
                                layer.alert(result.msg, {icon: 7, anim: 6}, function (index) {
                                    //do something
                                    // parent.window.location.reload();
                                    layer.close(index);
                                });
                            }
                        },
                        error: function (result) {
                            //未知异常操作
                            layer.msg("未知异常")
                        }
                    });
                }
                break;
            //点击图文接单
            case 'lookTw':
                layer.msg("正在连接中..")

                //调用抢单接口
                var rid = data.id;
                var ring2ly = data.ly;
                var ring2IP = data.ip;
                var ring2ym = data.yuming;
                var doctorId = $.cookie("doctorId");
                var userId = '';
                var tmpRoomId = data.id;
                var fwqbm = 'yjyl';
                if (ring2ly == "2") {
                    serverIP = ring2IP;
                    serverApi = "https://" + ring2ym + "/a02";
                    serverApi3 = "https://" + ring2ym + "/a03";
                    serverApi1 = "https://" + ring2ym + "/a01";
                    socketUrl6 = "wss://" + ring2ym + "/wss/websocket";
                    // dengMp3.pause();//暂停播放提示音
                    // layer.close(qangIndex);
                    // qangIndex = "";
                    //域外
                    //医生更换id
                    var reqData = {fwqbm: fwqbm, doctorId: doctorId};
                    $.ajax({
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                        url: serverApi + "/zy/findSysDoctorByFwqbmId" + "?" + formatParams(reqData),
                        success: function (result) {
                            console.log(JSON.stringify(result));
                            if (result.code === 200) {
                                doctorId = result.data;
                                userId = "doctor" + doctorId;

                                tmpRoomId = rid;
                                //普通接听
                                $.ajax({
                                    url: serverApi + "/omsring/RefuseTw?doctorId=" + doctorId + "&twid=" + data.id,
                                    type: "POST",
                                    success: function (result) {
                                        if (result.code === 200) {
                                            console.log(data)
                                            let findChatList = {
                                                "ly": data.ly,
                                                "doctorId": doctorId,
                                                "twid": data.id,
                                                // "aid": data.doctorAid,
                                                // "bid": 'd' + data.doctorAid,
                                                // "zhenid": data.id
                                                "serverIP": serverIP,
                                                "serverApi": serverApi,
                                                "serverApi3": serverApi3,
                                                "serverApi1": serverApi1,
                                                "socketUrl6": socketUrl6,
                                            };
                                            sessionStorage.setItem('findChatList', JSON.stringify(findChatList));
                                            let obj = {
                                                "roomId": data.id,
                                                "memberId": data.memberId,
                                                "sourceId": data.sourceId,
                                                "ly": data.ly,
                                                "ip": data.ip,
                                                "rctid": data.rctid,
                                                "yuming": data.yuming,
                                                "fwqmc": data.fwqmc,
                                                // "fwqbm": fwqbm,
                                                "ring2rctid": ring2rctid,
                                                "doctorId": doctorId,
                                                "userId": userId,
                                                "serverIP": serverIP,
                                                "serverApi": serverApi,
                                                "serverApi3": serverApi3,
                                                "serverApi1": serverApi1,
                                                "socketUrl6": socketUrl6,
                                            };
                                            sessionStorage.setItem('obj', JSON.stringify(obj));

                                            //设置为连接状态，连接结束前无法再抢单
                                            sessionStorage.setItem('tcpLink', "linking");

                                            var ring = result.data;
                                            $.cookie('memberId', ring.fmemberId, {path: '/'});
                                            $.cookie('memberSid', ring.sid, {path: '/'});
                                            let memberData = {
                                                "age": ring.age,
                                                "bloodPressure": ring.bloodPressure,
                                                "bloodSugar": ring.bloodSugar,
                                                "bodyFat": ring.bodyFat,
                                                "bqList": ring.bqList,//用户标签数组
                                                "bsList": ring.bsList,//用户标签图片 字符串数组
                                                "conditionDescription": ring.conditionDescription,//病情描述
                                                "yaodianId": ring.cyydId,//常用药店id
                                                // "chiefComplaint": ring.chiefComplaint,//主诉
                                                "diagnosisDisease": ring.diagnosisDisease,
                                                "diagnosis": ring.diagnosis,
                                                "diagnosisId": ring.diagnosisId,//就诊记录id
                                                "memberId": ring.fmemberId,//主患者id
                                                "familyHistory": ring.familyHistory,//家族病史
                                                "gender": ring.gender,//0未知,1男,2女
                                                "heartRate": ring.heartRate,
                                                "height": ring.height,//身高
                                                "historyDrugAllergy": ring.historyDrugAllergy,//过敏史
                                                "historySurgeryTrauma": ring.historySurgeryTrauma,//既往病史
                                                "icon": ring.icon,
                                                "name": ring.name,//昵称
                                                "orderId": ring.orderId,//问诊订单id
                                                "fqPanelType": ring.panelType,//发起来源，1小程序，2app，3客户端
                                                "pastMedicalHistory": ring.pastMedicalHistory,//慢病
                                                "yaodianName": ring.pharmacyName,//常用药店名称
                                                "phone": ring.phone,//手机号
                                                "sfbd": ring.sfbd,//此患者是否当前医生的私有患者
                                                "sid": ring.sid,//身份证号
                                                "sourceType": ring.sourceType,//权益来源 电信 移动 联通
                                                "symptomDuration": ring.symptomDuration,
                                                "visitRecords": ring.visitRecords,
                                                "weight": ring.weight,//体重

                                                // "lsList": ring.lsList,
                                                // "fqType": ring.type,//当来源是客户端时，1药店，2机构
                                                // "yaoList": ring.yaoList,//药品列表
                                                "pictureIllness": ring.pictureIllness,
                                            };
                                            sessionStorage.setItem('memberData', JSON.stringify(memberData));

                                            sessionStorage.setItem("changeLeft", true);
                                            parent.window.location.reload();
                                        } else {
                                            //抢单失败操作
                                            layer.alert(result.msg, {icon: 7, anim: 6})
                                        }
                                    }
                                });


                            } else {
                                layer.msg("外部服务器调用失败：" + result.msg);
                            }
                        },
                        error: function (e) {
                            console.error("获得外部医生id失败！");
                        }
                    });
                    //域内
                } else {
                    //普通接听
                    $.ajax({
                        url: serverApi + "/omsring/RefuseTw?doctorId=" + doctorId + "&twid=" + data.id,
                        type: "POST",
                        success: function (result) {
                            if (result.code === 200) {
                                console.log(data)
                                let findChatList = {
                                    "ly": data.ly,
                                    "doctorId": doctorId,
                                    "twid": data.id,
                                    // "aid": data.doctorAid,
                                    // "bid": 'd' + data.doctorAid,
                                    // "zhenid": data.id
                                    "serverIP": serverIP,
                                    "serverApi": serverApi,
                                    "serverApi3": serverApi3,
                                    "serverApi1": serverApi1,
                                    "socketUrl6": socketUrl6,
                                };
                                sessionStorage.setItem('findChatList', JSON.stringify(findChatList));
                                let obj = {
                                    "roomId": data.id,
                                    "memberId": data.memberId,
                                    "sourceId": data.sourceId,
                                    "ly": data.ly,
                                    "ip": data.ip,
                                    "rctid": data.rctid,
                                    "yuming": data.yuming,
                                    "fwqmc": data.fwqmc,
                                    // "fwqbm": fwqbm,
                                    "ring2rctid": ring2rctid,
                                    "doctorId": doctorId,
                                    "userId": userId,
                                    "serverIP": serverIP,
                                    "serverApi": serverApi,
                                    "serverApi3": serverApi3,
                                    "serverApi1": serverApi1,
                                    "socketUrl6": socketUrl6,
                                };
                                sessionStorage.setItem('obj', JSON.stringify(obj));

                                //设置为连接状态，连接结束前无法再抢单
                                sessionStorage.setItem('tcpLink', "linking");

                                var ring = result.data;
                                $.cookie('memberId', ring.fmemberId, {path: '/'});
                                $.cookie('memberSid', ring.sid, {path: '/'});
                                let memberData = {
                                    "age": ring.age,
                                    "bloodPressure": ring.bloodPressure,
                                    "bloodSugar": ring.bloodSugar,
                                    "bodyFat": ring.bodyFat,
                                    "bqList": ring.bqList,//用户标签数组
                                    "bsList": ring.bsList,//用户标签图片 字符串数组
                                    "conditionDescription": ring.conditionDescription,//病情描述
                                    "yaodianId": ring.cyydId,//常用药店id
                                    // "chiefComplaint": ring.chiefComplaint,//主诉
                                    "diagnosisDisease": ring.diagnosisDisease,
                                    "diagnosis": ring.diagnosis,
                                    "diagnosisId": ring.diagnosisId,//就诊记录id
                                    "memberId": ring.fmemberId,//主患者id
                                    "familyHistory": ring.familyHistory,//家族病史
                                    "gender": ring.gender,//0未知,1男,2女
                                    "heartRate": ring.heartRate,
                                    "height": ring.height,//身高
                                    "historyDrugAllergy": ring.historyDrugAllergy,//过敏史
                                    "historySurgeryTrauma": ring.historySurgeryTrauma,//既往病史
                                    "icon": ring.icon,
                                    "name": ring.name,//昵称
                                    "orderId": ring.orderId,//问诊订单id
                                    "fqPanelType": ring.panelType,//发起来源，1小程序，2app，3客户端
                                    "pastMedicalHistory": ring.pastMedicalHistory,//慢病
                                    "yaodianName": ring.pharmacyName,//常用药店名称
                                    "phone": ring.phone,//手机号
                                    "sfbd": ring.sfbd,//此患者是否当前医生的私有患者
                                    "sid": ring.sid,//身份证号
                                    "sourceType": ring.sourceType,//权益来源 电信 移动 联通
                                    "symptomDuration": ring.symptomDuration,
                                    "visitRecords": ring.visitRecords,
                                    "weight": ring.weight,//体重

                                    // "lsList": ring.lsList,
                                    // "fqType": ring.type,//当来源是客户端时，1药店，2机构
                                    // "yaoList": ring.yaoList,//药品列表
                                    "pictureIllness": ring.pictureIllness,
                                };
                                sessionStorage.setItem('memberData', JSON.stringify(memberData));

                                sessionStorage.setItem("changeLeft", true);
                                parent.window.location.reload();
                            } else {
                                //抢单失败操作
                                layer.alert(result.msg, {icon: 7, anim: 6})
                            }
                        }
                    });
                }


                break;
        }
    });
});